'use strict';

angular.module('subscriberAdmob', [])
		.run(function () {

			// skip if there is no connection
			if (navigator.connection.type == Connection.NONE) {
				return false;
			}



			var admobid;

			if (device.platform == 'Win32NT') {
				// wp8
				admobid = {
					banner: 'ca-app-pub-6465819007267041/1680912416',
					interstitial: 'ca-app-pub-6465819007267041/3157645611'
				};
			} else {
				//android
				admobid = {
					banner: '...',
					interstitial: '...'
				};
			}

			window.plugins.AdMob.setOptions({
				bannerAtTop: false, // set to true, to put banner at top
				overlap: false, // set to true, to allow banner overlap webview
				offsetTopBar: false, // set to true to avoid ios7 status bar overlap
				isTesting: false, // receiving test ad
				autoShow: true, // auto show interstitial ad when loaded
				publisherId: admobid.banner,
				interstitialAdId: admobid.interstitial
			});





			document.addEventListener('appready', function () {
				setTimeout(function () {
					// display the banner ads
					console.log('ads interstital');
					window.plugins.AdMob.createInterstitialView();
				}, 2000);

			}, false);



//			var eventGameStart = 0;
//			document.addEventListener('gamestart', function () {
//				eventGameStart++;
//
//				// popup ad every secund game start
//				if (eventGameStart % 2 === 1) {
//					console.log('ads interstitial');
//					// display the interstitial ads
//					window.plugins.AdMob.createInterstitialView();
//				}
//			}, false);

			console.log('subscriberAdmob::run');
		});